package com.dyava.commons.lang;

import java.util.Collection;

/**
 * Created by jjliu on 2018/2/4.
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {
    /**
     * 去除前后的字符
     * @param str
     * @param c
     * @return
     */
    public static String trim(String str,char c){
        if(isEmpty(str)){
            return str;
        }
        int startIndex = 0;
        int endIndex = str.length();
        for(int i=0;i<=endIndex;i++){
            startIndex =i;
            if(i==endIndex || str.charAt(i)!=c){
                break;
            }
        }
        for(int j=endIndex-1;j>=startIndex;j--){
            endIndex =j+1;
            if(str.charAt(j)!=c){
                break;
            }
        }
        String _str = str.substring(startIndex,endIndex);
        return _str;
    }

    public static String join(Collection<?> array,char split,char quot){
        if (array == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for(Object o : array){
            if(sb.length()>0){
                sb.append(split);
            }
            sb.append(quot).append(o.toString()).append(quot);
        }
        return sb.toString();
    };
}
